1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Superfolia | source code

superfolia9

# Author: Tom De Smedt, 2006
 
zoom = 3
size(2012.6/zoom, 2863/zoom)
 
bg = [
 color(0.70, 0.70, 0.65),
 color(0.97, 0.97, 0.92)
]
 
colors = [
 color(0.57, 0.57, 0.44),
 color(0.29, 0.27, 0.08),
 color(0.16, 0.16, 0.05),
 color(0, 0, 0),
 color(0, 0, 0)
]
colors.reverse()
 
# Given a list of colors,
# calculate intermediary steps.
# The plants go from black to green,
# giving them a nice sense of depth.
def gradient(colors, i, n):
 l = len(colors)-1
 a = int(1.0*i/n*l)
 a = min(a+0, l)
 b = min(a+1, l)
 base = 1.0 * n/l * a
 d = (i-base) / (n/l)
 r = colors[a].r*(1-d) + colors[b].r*d
 g = colors[a].g*(1-d) + colors[b].g*d
 b = colors[a].b*(1-d) + colors[b].b*d
 return color(r, g, b)
 
# Radial gradient background.
from math import sqrt
n = 800/zoom
r = sqrt(WIDTH*WIDTH + HEIGHT*HEIGHT)
for i in range(n):
 dx = (WIDTH-r)/2
 dy = (HEIGHT-r)/2
 fill(gradient(bg, i, n))
 oval(dx+i, dy+i, r-i*2, r-i*2)
 
svg = ximport("svg")
paths = svg.parse(open("plant.svg").read())
points = 100 # this will take a while to render.
 
nofill()
stroke(0)
strokewidth(0.5)
transform(CORNER)
scale(4.5 / zoom)
translate(-110, 35)
 
# Quick preview of the SVG:
#for path in paths:
# if random() > 0.25:
# drawpath(path)
 
for path in paths:
 if path.length > 900:
 n = points * 2
 d = 10
 else:
 n = points
 d = 30
 
 prev = None
 autoclosepath(False)
 nofill()
 for i, pt in zip(range(n), path.points(n)):
 
 clr = gradient(colors, i, n)
 clr.alpha = 0.7 + random(0.3)
 stroke(clr)
 strokewidth(random(0.04,0.2) * zoom)
 
 if prev != None:
 beginpath(prev.x, prev.y)
 curveto(
 pt.ctrl1.x - random(d), 
 pt.ctrl1.y,
 pt.ctrl2.x, 
 pt.ctrl2.y + random(d),
 pt.x, 
 pt.y
 )
 curveto(
 pt.ctrl1.x + random(d/3), 
 pt.ctrl1.y,
 pt.ctrl2.x, 
 pt.ctrl2.y - random(d/3),
 pt.x + random(-d*2/3, d*2/3), 
 pt.y + random(-d/3, d/3)
 )
 endpath()
 prev = pt

AltStyle によって変換されたページ (->オリジナル) /